package geektime.spring.springbucks.controller;

import geektime.spring.springbucks.service.CoffeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.UncategorizedSQLException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/intercept")
public class InterceptController {
    @Autowired
    private CoffeeService service;

    @GetMapping("/interceptFilter")
    public String interceptFilter(String sql) {
        try {
            service.interceptFilter(sql);
            return "执行成功";
        } catch (UncategorizedSQLException ex) {
            return ex.getRootCause().getMessage();
        } catch (Exception ex) {
            return ex.getMessage();
        }
    }
}
